package com.meng.system.controller.auth;


import com.meng.system.domain.vo.ResponseVO;
import com.meng.system.domain.vo.SysDeptVO;
import com.meng.system.enums.ErrorEnum;
import com.meng.system.service.auth.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 部门管理 前端控制器
 * @author: Xu Meng
 * @program: minions-cloud
 * @create: 2021-01-14 23:06
 **/
@Api(tags = "部门管理")
@Slf4j
@RestController
@RequestMapping("/sysDept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @ApiOperation(value = "保存部门信息")
    @PostMapping(value = "/save")
    public ResponseVO<?> save(@RequestBody SysDeptVO sysDept){
        return ResponseVO.result(ErrorEnum.SUCCESS,sysDeptService.save(sysDept));
    }

    @ApiOperation(value = "获取所有部门信息")
    @GetMapping(value = "/findDeptList")
    public ResponseVO<?> findDeptList(){
        return ResponseVO.result(ErrorEnum.SUCCESS,sysDeptService.list());
    }

    @ApiOperation(value = "获取部门树")
    @GetMapping(value = "/getDeptTree")
    public ResponseVO<?> getDeptTree(){
        return ResponseVO.result(ErrorEnum.SUCCESS,sysDeptService.getDeptTree());
    }

    @ApiOperation(value = "更新部门信息")
    @PutMapping
    public ResponseVO<?> updateDept(@RequestBody SysDeptVO sysDept){
        return ResponseVO.result(ErrorEnum.SUCCESS,sysDeptService.updateById(sysDept));
    }

    @ApiOperation("根据id删除部门信息")
    @DeleteMapping("/{id}")
    public ResponseVO<?> delete(@PathVariable("id") Integer id){
        return ResponseVO.result(ErrorEnum.SUCCESS,sysDeptService.removeById(id));
    }
}

